package org.yang.admin.controller;

import groovy.util.logging.Slf4j;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.yang.admin.common.convention.result.Result;
import org.yang.admin.common.convention.result.Results;
import org.yang.admin.dto.req.ShortLinkGroupSaveReqDTO;
import org.yang.admin.dto.req.ShortLinkGroupSortReqDTO;
import org.yang.admin.dto.req.ShortLinkGroupUpdateReqDTO;
import org.yang.admin.dto.resp.ShortLinkGroupRespDTO;
import org.yang.admin.service.GroupService;

import java.util.List;

@RestController

@Slf4j
@RequiredArgsConstructor
public class GroupController {

    private final GroupService groupService;

    /**
     * 保存分组
     * @param requestParam
     */
    @PostMapping("/api/short-link/admin/v1/group")
    public Result<Void> save(@RequestBody ShortLinkGroupSaveReqDTO requestParam){
        groupService.save(requestParam);
        return Results.success();
    }

    /**
     * 分组列表
     */
    @GetMapping("/api/short-link/admin/v1/group/groupList")
    public Result<List<ShortLinkGroupRespDTO>> groupList(){
        return Results.success(groupService.groupList());
    }

    /**
     * 更新分组
     */
    @PutMapping("/api/short-link/admin/v1/group")
    public Result<Void> updateGroup(@RequestBody ShortLinkGroupUpdateReqDTO requestParam){
        groupService.updateGroup(requestParam);
        return Results.success();
    }

    /**
     * 删除分组
     */
    @DeleteMapping("/api/short-link/admin/v1/group")
    public Result<Void> deleteGroup(@RequestParam String gid){
        groupService.deleteGroup(gid);
        return Results.success();
    }

    /**
     * 短链接分组排序
     */
    @PostMapping("/api/short-link/admin/v1/group/sort")
    public Result<Void> sort(@RequestBody List<ShortLinkGroupSortReqDTO> requestParam){
        groupService.sort(requestParam);
        return Results.success();
    }

}
